package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.TeacherDao;
import com.itheima.edu.info.manager.domain.Teacher;

public class TeacherService {
    private TeacherDao  teacherDao= new TeacherDao();
    public static boolean addTeacher(Teacher stu){
        return TeacherDao.addTeacher(stu);
    }
    public static boolean isExists(String id) {
        Teacher[] stus = TeacherDao.findAllStudent();
        boolean exists = false;
        for (int i = 0; i <stus.length ; i++) {
            Teacher teacher = stus[i];
            if (teacher !=  null &&teacher.getId().equals(id)){
                exists = true;
                break;
            }

        }
        return exists;
    }

    public static void updateStudent(String updateId, Teacher newStu) {
        TeacherDao.updateStudent(updateId,newStu);
    }

    public void deleteTeacherById(String delId) {
        TeacherDao.deleteTeacherById(delId);
    }

    public Teacher[] findAllTeacher() {
        Teacher[] allTeacher = TeacherDao.findAllTeacher();
        boolean flag = false;
        for (int i = 0; i <allTeacher.length ; i++) {
            Teacher stu = allTeacher[i];
            if (stu != null){
                flag=true;
                break;
            }
        }
        if (flag){
            return allTeacher;
        }else {
            return  null;
        }
    }
}
